1. Field of the Invention
The present invention relates generally to a data processing system and in particular to a method and system for virtual memory. More particularly, the present invention is directed to a computer implemented method, apparatus, and computer-usable program code for adjusting the page size in a virtual memory range.
2. Description of the Related Art
Many modern operating systems use a page-based virtual memory architecture in which virtual memory is mapped to primary memory, such as random access memory, in units of fixed-page size. Primary memory may also be referred to as main memory. Page-based virtual memory refers to the process of managing program access to virtual memory pages that do not currently reside in a primary memory. A virtual memory page resides on primary memory when the virtual memory page is translated to primary memory. A virtual memory page is translated to the primary memory when the virtual memory page is referenced by an application.
Some computer architectures and operating systems provide support for multiple page sizes. Larger page sizes can improve the performance of hardware translation mechanisms because they allow hardware translation caches to translate larger amounts of memory. However, operating systems that support multiple different page sizes face the problem of choosing the optimal page size for a workload. Current operating systems attempt to solve this problem in a number of different ways.
Some operating systems use the largest supported page size at all times regardless of system conditions. However, using the largest page size at all times can waste memory resources by creating a needlessly large memory footprint for a workload. For example, an application that declares an array of data that is 64K bytes in size may only use the first 8K bytes of the array. However, if an operating system maps the entire 64K byte range with a 64K byte page, the range would consume a full 64K bytes of primary memory even though only 8K bytes of the data array is used. Hence, memory resources are wasted by this method.
Another current method implemented by some operating systems allows a user or application developer to select a static page size via an application programming interface (API) or environmental variable. However, allowing a user or application developer to select a static page size for an application using an API requires that the application be modified and re-compiled in order to use the API. Also, when a larger page size is selected using this method, applications that expect a smaller page size may fail when performing some page-level operations, such as setting page protections using the mprotect( ) function. Another disadvantage to this method is that the page selection is static and does not respond to changing system conditions, such as whether the primary memory is over-committed.
Another currently available method samples an application workload and then makes a page size decision based on the sampled workload data. In this method, performance metrics, such as translation cache misses, are gathered. When the application is re-run, larger page sizes are used for the selected memory pages based on the performance metrics that were gathered during the previous run of the application. However, this method has the disadvantage of having to run an application multiple times to determine an optimal page size to use for the application. Also, gathering performance metrics for an application can be an inconvenient and burdensome task. Furthermore, this method can only be used to select page sizes for an application at the time the application is started, as opposed to dynamically selecting pages sizes during application runtime. Therefore, this method represents a static approach to selecting a page size.